package com.fengke.cn.yejian11.fragment;


import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import com.fengke.cn.yejian11.R;
import com.fengke.cn.yejian11.adapter.ClubVideoAdapter;
import com.fengke.cn.yejian11.config.Config;
import com.fengke.cn.yejian11.impls.ActImpls;
import com.fengke.cn.yejian11.javabean.ClubCourse;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
/**
 * A simple {@link Fragment} subclass.
 */
public class ClubCourseFragment extends Fragment {

    private RecyclerView recyclerView;
    private Retrofit retrofit;
    private ClubVideoAdapter adapter;
    private List<ClubCourse> courseList;

    private String map;
    private String Club_Id;


    public ClubCourseFragment() {
        // Required empty public constructor
    }


    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState){
        super.onViewCreated(view, savedInstanceState);

        Club_Id=getActivity().getIntent().getStringExtra("Club_Id");
        map="Clubcourse";

        recyclerView= (RecyclerView) view.findViewById(R.id.club_info_course);
        retrofit=new Retrofit.Builder()
                .baseUrl(Config.URL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        ActImpls service=retrofit.create(ActImpls.class);
        retrofit2.Call<ClubCourse> call=service.getClubCourse(Club_Id,map);
        call.enqueue(new Callback<ClubCourse>() {
            @Override
            public void onResponse(Call<ClubCourse> call, Response<ClubCourse> response) {
                List<ClubCourse.ClubcourseEntity> res=response.body().getClubcourse();
                adapter = new ClubVideoAdapter(getActivity(),res);
                LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity());
                linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
                recyclerView.setLayoutManager(linearLayoutManager);
                recyclerView.setAdapter(adapter);
                recyclerView.setItemAnimator(new DefaultItemAnimator());
            }

            @Override
            public void onFailure(Call<ClubCourse> call, Throwable t) {

                Toast.makeText(getActivity(),"获取列表失败",Toast.LENGTH_SHORT).show();
            }
        });
    }




    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_club_course, container, false);
    }

}
